package com.hzw.rest;

import com.hzw.api.ICommodityTypeService;
import com.hzw.entity.CommodityType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@CrossOrigin
@RequestMapping("commodityType")
public class CommodityTypeController {

    @Autowired
    ICommodityTypeService commodityTypeService;

    /**
     * 查询全部商品分类
     * @param commodityType
     * @return
     */
    @PostMapping("selectAll")
    @ResponseBody
    public List<CommodityType> selectAll(@RequestBody CommodityType commodityType) {
        return commodityTypeService.selectAll(commodityType);
    }

    /**
     * 通过Id查询（回显功能）
     *
     * @return
     */
    @PostMapping("selectById")
    @ResponseBody
    public CommodityType selectById(@RequestBody CommodityType commodityType) {
        return commodityTypeService.selectById(commodityType);
    }
    /**
     * 更新商品分类信息
     *
     * @param commodityType
     */
    @PostMapping("update")
    @ResponseBody
    public void update(@RequestBody CommodityType commodityType) {
        commodityTypeService.updateById(commodityType);
    }

    /**
     * 删除商品分类
     *
     * @param commodityType
     */
    @PostMapping("delete")
    @ResponseBody
    public void delById(@RequestBody CommodityType commodityType) {
        commodityTypeService.delById(commodityType);
    }

    /**
     * 新增商品分类
     * @param commodityType
     */
    @PostMapping("insert")
    @ResponseBody
    public int insert(@RequestBody CommodityType commodityType) {
        return commodityTypeService.insert(commodityType);
    }

}
